package com.mybatis.dao;

import com.mybatis.bean.Book;
import com.mybatis.bean.Publisher;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface BookDao {
    List<Book> findAllBook();

    List<Book> findAllBookByPublisher(Publisher publisher);

    List<Book> findAllBookLazyLoading();

    Book findBookById(Integer id);

    Book findBookByIdLazyLoading(Book book);

    void addBook(Book book);

    void deleteBookByIds(List<Integer> list);

    List<Book> findBookByIds(List<Integer> idList);

    List<Book> findBookByIds2(Integer[] ids);

    void updateBookInfo(Book book);


    @Select("select * from tb_book where bookId = ${id121}")
    @Results(id = "book2", value = {
            @Result(property = "book_id", column = "bookId", id = true),
            @Result(property = "book_name", column = "bookName")
    })
    List<Book> findAllBook2(Integer id);

    @ResultMap({"book2"})
    @Select("select * from tb_book where bookId=${book_id}")
    List<Book> findBookById2(Integer id);

    @Select("select * from tb_book")
    @Results(id = "bookWithPublisherMap", value = {
            @Result(property = "book_id", column = "bookId", id = true),
            @Result(property = "book_name",column = "bookName"),
            @Result(property = "book_price",column = "bookPrice"),
            @Result(property = "publish_time",column = "publishTime"),
            @Result(property = "pub" ,column = "publisherId",one = @One(select = "com.mybatis.dao.PublisherDao.findPublisherById2",fetchType = FetchType.EAGER))
    })
    List<Book> findBookWithPublisher();


    Book findBookByNotOneParam (Integer book_id,String book_name);
}
